package demo.practice.tree.depth;

import demo.practice.TreeNode;

public class P112 {

    public static void main(String[] args) {

        TreeNode root = new TreeNode(1);


    }

    public boolean hasPathSum(TreeNode root, int targetSum) {
        return hasPathSumDepth(root, targetSum, 0);
    }
    public boolean hasPathSumDepth(TreeNode root, int targetSum, int sum) {
        if (root != null) {
            if (root.left == null && root.right == null)
                return (sum + root.val) == targetSum;

            if (hasPathSumDepth(root.right, targetSum, sum + root.val))
                return true;

            return hasPathSumDepth(root.left, targetSum, sum + root.val);
        }
        return false;
    }


}
